<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript" src="js/tools.js">
			
		</script>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			
			#outer{
				width: 520px;
				height: 333px;
				background-color: pink;
				padding: 10px 0 ;
				margin: 50px auto;
				position: relative;
				overflow: hidden;
				
			}
			
			#imgList{
				list-style: none;
				position: absolute;
				left: 0;
			}
			
			#imgList li{
				float: left;
				margin:0 10px;
				
			}
			
			#navDiv{
				position:absolute;
				bottom: 15px;
			}
			#navDiv a{
				float: left;
				margin: 0 5px;
				width: 15px;
				height: 15px;
				background-color: red;
				opacity: 0.5;
				/*兼容IE版本*/
				filter: alpha(opacity=50);
				
			}
		</style>
		
		<script type="text/javascript">
			window.onload = function(){
				//获取outer
				var outer = document.getElementById("outer"); 
				//获取照片父元素
				var imgList = document.getElementById("imgList");
				//获取所有子元素
				var imgArr = document.getElementsByTagName("img");
				//改变元素的宽度
				imgList.style.width = imgArr.length * 520 +"px" ;
				
				//获取navDiv
				var navDiv = document.getElementById("navDiv");
				//获取所有a
				var allA = document.getElementsByTagName("a");
				//改变小圆点的位置
				navDiv.style.left = (outer.offsetWidth - navDiv.offsetWidth) / 2 + "px";
				
				//设置索引值为0
				 var index = 0;
				
				//设置默认的选中效果
				allA[index].style.backgroundColor = "black";
				
				//遍历所有a
				for(var i=0 ; i<allA.length; i++){
					allA[i].num = i;
					
					
					allA[i].onclick = function(){
						
						clearInterval(timer);
						index = this.num;
						
						//设置小圆点的样式
						setA();
						//调用函数切换图片
						move(imgList, "left", -520*index, 20, function(){
							autoChange();
						});
					};
					
					
				}
				
				autoChange();
				
				function setA(){
					
					//如果是最后一张，将他换成第一张
					if(index >= imaArr.length - 1){
						index = 0;
						
						imgList.style.left = 0;
					}
					
					
					
					for(var i=0 ; i<allA.length; i++){
						allA[i].style.backgroundColor = "";
					}
					allA[index].style.backgroundColor = "black";
				
				};
				
				var timer;
				
				function autoChange(){
					timer = setInterval(function(){
						index++;
						
						index %= imgArr.length;
						
						move(imgList, "left",-520*index,20,function(){
							setA();
						});
					},3000);
				}
			};
			
			
		</script>
	</head>
	<body>
		<!--创建外面大的容器-->
		<div id="outer">
			<!--创建照片的无序列表-->
			<ul id="imgList">
				<li><img src="img/dl.jpg"/></li>
				<li><img src="img/1.jpg"/></li>
				<li><img src="img/2.jpg"/></li>
				<li><img src="img/3.jpg"/></li>
				<li><img src="img/4.jpg"/></li>
				<li><img src="img/5.jpg"/></li>
				<li><img src="img/dl.jpg"/></li>
			</ul>
			
			<!--创建小圆点-->
			<div id="navDiv">
				<a href="javascript:;"></a>
				<a href="javascript:;"></a>
				<a href="javascript:;"></a>
				<a href="javascript:;"></a>
				<a href="javascript:;"></a>
				<a href="javascript:;"></a>
			</div>
		</div>
	</body>
</html>
